Skip to content

Comments

WA-NEW-004: Fix metrics week calculations across DST#648

Open
kitcommerce wants to merge 2 commits intonextfrom
wa-new-004-metrics-dst
Open

WA-NEW-004: Fix metrics week calculations across DST#648
kitcommerce wants to merge 2 commits intonextfrom
wa-new-004-metrics-dst

Conversation

@kitcommerce
Copy link

Closes #644.\n\nExtracted from stacked PRs #630/#631 to make merge order linear.

@kitcommerce
Copy link
Author

Dispatcher Build Gate Summary (local)

  • rubocop (diff-only): PASS (0 offenses)
  • brakeman: skipped (per repo build gate config; disabled)
  • tests (affected engines): PASS
    • core: PASS

Note: test output still prints BSON Symbol deprecation warning (expected to be addressed by WA-NEW-010 / PR #635).

@kitcommerce kitcommerce added review:architecture-pending Architecture review in progress review:test-quality-pending Test quality review in progress review:performance-pending Performance review in progress review:architecture-done Architecture review complete review:test-quality-done Test quality review complete and removed review:architecture-pending Architecture review in progress review:test-quality-pending Test quality review in progress labels Feb 21, 2026
@kitcommerce
Copy link
Author

Architecture Review

Verdict: PASS_WITH_NOTES (LOW)

Contained metrics-layer change; DST-safe week math via date-based calculations is the right direction.

Note

  • core/app/models/workarea/metrics/by_week.rb:16 — Week boundary logic now exists in multiple places (scope + scoring). If definitions change later, logic could drift.
    • Suggestion: consider centralizing week boundary/week-diff helpers (small module/private method) to keep one definition.

@kitcommerce
Copy link
Author

Test Quality Review

Verdict: CHANGES_REQUIRED (MEDIUM)

The DST regression coverage added in test_weeks_ago is good, but there are still travel_to calls in this file that are not in block form and can leak frozen time across tests.

Findings

  • core/test/models/workarea/metrics/product_by_week_test.rb:15travel_to in test_last_week is called without a block, so time may not be restored automatically.

    • Fix: use travel_to(...) do ... end (or ensure travel_back) so time state is always reset.
  • core/test/models/workarea/metrics/product_by_week_test.rb:112 — Same issue in test_score.

    • Fix: convert to block form.

Once those are block-form, the suite should be much more robust against ordering/flakiness.

@kitcommerce
Copy link
Author

Fix applied for test-quality feedback

Pushed fix to branch wa-new-004-metrics-dst to address non-block-form travel_to calls leaking time across tests.

  • Converted travel_to in test_last_week and test_score to block form.
  • Verified: bundle exec ruby -Icore/test core/test/models/workarea/metrics/product_by_week_test.rb

Commit: c68b08d

@kitcommerce kitcommerce added review:test-quality-pending Test quality review in progress review:architecture-pending Architecture review in progress review:performance-pending Performance review in progress review:test-quality-done Test quality review complete and removed review:architecture-done Architecture review complete review:test-quality-done Test quality review complete review:performance-pending Performance review in progress review:architecture-pending Architecture review in progress review:test-quality-pending Test quality review in progress labels Feb 21, 2026
@kitcommerce kitcommerce added review:architecture-done Architecture review complete review:performance-done Performance review complete labels Feb 21, 2026
@kitcommerce
Copy link
Author

Test Quality Review (re-run)

Verdict: PASS

Re-check after commit c68b08d6: all travel_to usages in core/test/models/workarea/metrics/product_by_week_test.rb are now block-form, so time state is restored and cross-test leakage risk is low.

@kitcommerce
Copy link
Author

Architecture Review (re-run)

Verdict: PASS

Re-check after c68b08d6: fix is test-only (block-form travel_to); no new architectural concerns introduced. Prior note about possibly centralizing week-boundary helpers remains optional.

@kitcommerce
Copy link
Author

Performance Review

Verdict: PASS

Performance risk is low. Date-based week boundaries keep the query as an indexed range scan on reporting_on and avoid DST drift; Ruby-side conversions are negligible.

@kitcommerce kitcommerce added the merge:ready All conditions met, eligible for merge label Feb 21, 2026
@kitcommerce
Copy link
Author

✅ Review summary

Re-review after fix commit c68b08d6:

  • Test quality: PASS
  • Architecture: PASS
  • Performance: PASS

Labeled merge:ready.

@kitcommerce
Copy link
Author

Performance Review

Verdict: PASS

Performance risk is low. Switching from second-based week math to date-based boundaries avoids DST drift and keeps DB queries as an indexed range scan on reporting_on. Ruby-side date conversions are negligible.

@kitcommerce
Copy link
Author

Architecture Review (re-run)

Verdict: PASS

Re-check after fix commit c68b08d6: test-only change (block-form travel_to), no new architectural concerns introduced. Optional previous note about centralizing week-boundary helpers remains non-blocking.

@kitcommerce
Copy link
Author

✅ Re-review status after c68b08d

  • Architecture: PASS
  • Performance: PASS

(Waiting on test-quality label if not yet updated.)

Labeled merge:ready.

@kitcommerce
Copy link
Author

✅ Re-review status after c68b08d

All requested follow-ups are satisfied and reviews are green:

  • Test quality: PASS
  • Architecture: PASS
  • Performance: PASS

Labeled merge:ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gate:build-passed Build gate passed merge:ready All conditions met, eligible for merge review:architecture-done Architecture review complete review:performance-done Performance review complete review:test-quality-done Test quality review complete

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant